package cn.hxzy.Controller;


import com.auth0.jwt.interfaces.Claim;
import org.springframework.web.bind.annotation.ModelAttribute;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Objects;

public class BaseController {

    protected HttpServletRequest request;
    protected HttpServletResponse response;
    protected Claim claim;

    @ModelAttribute
    //注释的方法会在此controller每个方法执行前被执行，因此对于一个controller映射多个URL的用法来说，要谨慎使用。
    public void setResAnReq(HttpServletRequest request,HttpServletResponse response) {
        this.request = request;
        this.response = response;

        Object obj = request.getAttribute("claim");

        if(obj != null) {
            this.claim = (Claim) obj;
        }
    }

}
